/*
 * Copyright 2013-2018 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.aoxiang.zbox.controller;

import com.aoxiang.zbox.common.model.Result;
import com.aoxiang.zbox.model.dto.LabelDTO;
import com.aoxiang.zbox.model.entity.Label;
import com.aoxiang.zbox.model.vo.SimpleLabelVO;
import com.aoxiang.zbox.service.LabelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/api/label")
public class LabelController {
    @Autowired
    private LabelService labelService;

    @PostMapping("/create")
    public Result<Long> createLabel(@RequestBody @Validated LabelDTO labelDto) {
        return Result.success(labelService.createLabel(labelDto));
    }

    @GetMapping("/list-all")
    public Result<List<Label>> listAll() {
        return Result.success(labelService.list());
    }

    @GetMapping("/remove")
    public Result<Boolean> removeLabel(@RequestParam("id") Long id) {
        return Result.success(labelService.removeById(id));
    }

    @PostMapping("/update")
    public Result<String> updateLabel(@RequestBody @Validated LabelDTO labelDto) {
        labelService.updateById(labelDto);
        return Result.success();
    }

    @GetMapping("/get-all")
    public Result<List<SimpleLabelVO>> getAllSimple() {
        return Result.success(labelService.getAllSimple());
    }

    @GetMapping("/get-shown")
    public Result<List<SimpleLabelVO>> getShownSimple() {
        return Result.success(labelService.getShownSimple());
    }

    @GetMapping("/add-show")
    public Result<String> addShow(@RequestParam("id") Long id) {
        labelService.addShow(id);
        return Result.success();
    }

    @PostMapping("/update-show-sort")
    public Result<String> updateShowSort(@RequestBody List<Long> ids) {
        labelService.updateShowSort(ids);
        return Result.success();
    }

    @PostMapping("/update-completed-sort")
    public Result<String> updateCompletedSort(@RequestBody List<Long> ids) {
        labelService.updateCompletedSort(ids);
        return Result.success();
    }

}
